<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">

    <link href="../../jquery/bootstrap_3.3.0/css/bootstrap.min.css" type="text/css" rel="stylesheet"/>
    <link href="../../jquery/bootstrap-datetimepicker-master/css/bootstrap-datetimepicker.min.css" type="text/css"
          rel="stylesheet"/>

    <!--分页插件的样式-->
    <link href="../../jquery/bs_pagination/jquery.bs_pagination.min.css" type="text/css" rel="stylesheet"/>
    <!--分页插件的样式End-->

    <script type="text/javascript" src="../../jquery/jquery-1.11.1-min.js"></script>
    <script type="text/javascript" src="../../jquery/bootstrap_3.3.0/js/bootstrap.min.js"></script>
    <script type="text/javascript"
            src="../../jquery/bootstrap-datetimepicker-master/js/bootstrap-datetimepicker.min.js"></script>
    <script type="text/javascript"
            src="../../jquery/bootstrap-datetimepicker-master/locale/bootstrap-datetimepicker.zh-CN.js"></script>

    <!--分页插件的脚本-->
    <script type="text/javascript" src="../../jquery/bs_pagination/jquery.bs_pagination.min.js"></script>
    <script type="text/javascript" src="../../jquery/bs_pagination/en.js"></script>
    <!--分页插件的脚本End-->


    <script type="text/javascript">

        $(function () {
            //以下日历插件在FF中存在兼容问题，在IE浏览器中可以正常使用。
            //定制字段
            $("#definedColumns > li").click(function (e) {
                //防止下拉菜单消失
                e.stopPropagation();
            });
        });

    </script>
</head>
<body>

<!-- 创建市场活动的模态窗口 -->
<div class="modal fade" id="createActivityModal" role="dialog">
    <div class="modal-dialog" role="document" style="width: 85%;">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">
                    <span aria-hidden="true">×</span>
                </button>
                <h4 class="modal-title" id="myModalLabel1">创建市场活动</h4>
            </div>
            <div class="modal-body">

                <form class="form-horizontal" role="form">

                    <div class="form-group">
                        <label for="create-marketActivityOwner" class="col-sm-2 control-label">所有者<span
                                style="font-size: 15px; color: red;">*</span></label>
                        <div class="col-sm-10" style="width: 300px;">
                            <select class="form-control" id="create-marketActivityOwner">
                                <option>zhangsan</option>
                                <option>lisi</option>
                                <option>wangwu</option>
                            </select>
                        </div>
                        <label for="create-marketActivityName" class="col-sm-2 control-label">名称<span
                                style="font-size: 15px; color: red;">*</span></label>
                        <div class="col-sm-10" style="width: 300px;">
                            <input type="text" class="form-control" id="create-marketActivityName">
                        </div>
                    </div>

                    <div class="form-group">
                        <label for="create-startTime" class="col-sm-2 control-label">开始日期</label>
                        <div class="col-sm-10" style="width: 300px;">
                            <input type="text" class="form-control" id="create-startTime">
                        </div>
                        <label for="create-endTime" class="col-sm-2 control-label">结束日期</label>
                        <div class="col-sm-10" style="width: 300px;">
                            <input type="text" class="form-control" id="create-endTime">
                        </div>
                    </div>
                    <div class="form-group">

                        <label for="create-cost" class="col-sm-2 control-label">成本</label>
                        <div class="col-sm-10" style="width: 300px;">
                            <input type="text" class="form-control" id="create-cost">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="create-describe" class="col-sm-2 control-label">描述</label>
                        <div class="col-sm-10" style="width: 81%;">
                            <textarea class="form-control" rows="3" id="create-describe"></textarea>
                        </div>
                    </div>

                </form>

            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" id="bbb" class="btn btn-default">关闭2</button>
                <button id="btnAdd" type="button" class="btn btn-primary">保存</button>
            </div>
        </div>
    </div>
</div>

<!-- 修改市场活动的模态窗口 -->
<div class="modal fade" id="editActivityModal" role="dialog">
    <div class="modal-dialog" role="document" style="width: 85%;">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">
                    <span aria-hidden="true">×</span>
                </button>
                <h4 class="modal-title" id="myModalLabel2">修改市场活动</h4>
            </div>
            <div class="modal-body">

                <form class="form-horizontal" role="form">

                    <div class="form-group">
                        <label for="edit-marketActivityOwner" class="col-sm-2 control-label">所有者<span
                                style="font-size: 15px; color: red;">*</span></label>
                        <div class="col-sm-10" style="width: 300px;">
                            <select class="form-control" id="edit-marketActivityOwner">
                                <option>zhangsan</option>
                                <option>lisi</option>
                                <option>wangwu</option>
                            </select>
                        </div>
                        <label for="edit-marketActivityName" class="col-sm-2 control-label">名称<span
                                style="font-size: 15px; color: red;">*</span></label>
                        <div class="col-sm-10" style="width: 300px;">
                            <input type="text" class="form-control" id="edit-marketActivityName" value="发传单">
                        </div>
                    </div>

                    <div class="form-group">
                        <label for="edit-startTime" class="col-sm-2 control-label">开始日期</label>
                        <div class="col-sm-10" style="width: 300px;">
                            <input type="text" class="form-control" id="edit-startTime" value="2020-10-10">
                        </div>
                        <label for="edit-endTime" class="col-sm-2 control-label">结束日期</label>
                        <div class="col-sm-10" style="width: 300px;">
                            <input type="text" class="form-control" id="edit-endTime" value="2020-10-20">
                        </div>
                    </div>

                    <div class="form-group">
                        <label for="edit-cost" class="col-sm-2 control-label">成本</label>
                        <div class="col-sm-10" style="width: 300px;">
                            <input type="text" class="form-control" id="edit-cost" value="5,000">
                        </div>
                    </div>

                    <div class="form-group">
                        <label for="edit-describe" class="col-sm-2 control-label">描述</label>
                        <div class="col-sm-10" style="width: 81%;">
                            <textarea class="form-control" rows="3" id="edit-describe">市场活动Marketing，是指品牌主办或参与的展览会议与公关市场活动，包括自行主办的各类研讨会、客户交流会、演示会、新产品发布会、体验会、答谢会、年会和出席参加并布展或演讲的展览会、研讨会、行业交流会、颁奖典礼等</textarea>
                        </div>
                    </div>

                </form>

            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button id="btnEdit" type="button" class="btn btn-primary">更新</button>
            </div>
        </div>
    </div>
</div>

<!-- 导入市场活动的模态窗口 -->
<div class="modal fade" id="importActivityModal" role="dialog">
    <div class="modal-dialog" role="document" style="width: 85%;">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">
                    <span aria-hidden="true">×</span>
                </button>
                <h4 class="modal-title" id="myModalLabel">导入市场活动</h4>
            </div>
            <div class="modal-body" style="height: 350px;">
                <div style="position: relative;top: 20px; left: 50px;">
                    请选择要上传的文件：<small style="color: gray;">[仅支持.xls或.xlsx格式]</small>
                </div>
                <div style="position: relative;top: 40px; left: 50px;">
                    <input type="file">
                </div>
                <div style="position: relative; width: 400px; height: 320px; left: 45% ; top: -40px;">
                    <h3>重要提示</h3>
                    <ul>
                        <li>给定文件的第一行将视为字段名。</li>
                        <li>请确认您的文件大小不超过5MB。</li>
                        <li>从XLS/XLSX文件中导入全部重复记录之前都会被忽略。</li>
                        <li>复选框值应该是1或者0。</li>
                        <li>日期值必须为MM/dd/yyyy格式。任何其它格式的日期都将被忽略。</li>
                        <li>日期时间必须符合MM/dd/yyyy hh:mm:ss的格式，其它格式的日期时间将被忽略。</li>
                        <li>默认情况下，字符编码是UTF-8 (统一码)，请确保您导入的文件使用的是正确的字符编码方式。</li>
                        <li>建议您在导入真实数据之前用测试文件测试文件导入功能。</li>
                    </ul>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary" data-dismiss="modal">导入</button>
            </div>
        </div>
    </div>
</div>


<div>
    <div style="position: relative; left: 10px; top: -10px;">
        <div class="page-header">
            <h3>市场活动列表</h3>
        </div>
    </div>
</div>


<!--内容区域	-->
<div style="position: relative; top: -20px; left: 0px; width: 100%; height: 100%;">
    <div style="width: 100%; position: absolute;top: 5px; left: 10px;">

        <!--查询按钮区域-->
        <div class="btn-toolbar" role="toolbar" style="height: 80px;">
            <form class="form-inline"  role="form" style="position: relative;top: 8%; left: 5px;">

                <div class="form-group">
                    <div class="input-group">
                        <div class="input-group-addon">名称</div>
                        <input id="name" class="form-control" type="text">
                    </div>
                </div>

                <div class="form-group" >
                    <div class="input-group">
                        <div class="input-group-addon">所有者</div>
                        <input id="owner" class="form-control" type="text">
                    </div>
                </div>


                <div class="form-group">
                    <div class="input-group">
                        <div class="input-group-addon">开始日期</div>
                        <input class="form-control" type="text" id="startTime"/>
                    </div>
                </div>

                <div class="form-group">
                    <div class="input-group">
                        <div class="input-group-addon">结束日期</div>
                        <input class="form-control" type="text" id="endTime">
                    </div>
                </div>


                <button id="btnSearch" type="button" class="btn btn-default">查询</button>
            </form>
        </div>


        <!-- 数据CRUD按钮区域-->
        <div class="btn-toolbar" role="toolbar"
             style="background-color: #F7F7F7; height: 50px; position: relative;top: 5px;">
            <div class="btn-group" style="position: relative; top: 18%;">
                <button id="btnShowAddModel" type="button" class="btn btn-primary">
                    <span class="glyphicon glyphicon-plus"></span> 创建
                </button>
                <button id="btnEditBefore" type="button" class="btn btn-default"><span
                        class="glyphicon glyphicon-pencil"></span> 修改
                </button>
                <button id="btnDel" type="button" class="btn btn-danger"><span class="glyphicon glyphicon-minus"></span>
                    删除
                </button>
            </div>
            <div class="btn-group" style="position: relative; top: 18%;">
                <button type="button" class="btn btn-default" data-toggle="modal" data-target="#importActivityModal">
                    <span class="glyphicon glyphicon-import"></span> 导入
                </button>
                <button type="button" class="btn btn-default"><span class="glyphicon glyphicon-export"></span> 导出
                </button>
            </div>
        </div>
        <!--表格数据显示区域-->
        <div style="position: relative;top: 10px;">
            <table id="table" class="table table-hover">
                <thead>
                <tr style="color: #B3B3B3;">
                    <td><input id="selectAll" type="checkbox"/></td>
                    <td>名称</td>
                    <td>所有者</td>
                    <td>开始日期</td>
                    <td>结束日期</td>
                </tr>
                </thead>
                <tbody>
                <tr class="active">
                    <td><input type="checkbox"/></td>
                    <td><a style="text-decoration: none; cursor: pointer;"
                           onclick="window.location.href='detail.html';">发传单</a></td>
                    <td>zhangsan</td>
                    <td>2020-10-10</td>
                    <td>2020-10-20</td>
                </tr>

                </tbody>
            </table>
        </div>

        <!--分页信息区域-->
        <div id="page"></div>


    </div>

</div>


</body>
</html>

<script>
    //查询所有
    //currentPage：当前页参数
    //rowsPerPage：每页显示行数
    //全查询
    function getAll(currentPage, rowsPerPage) {
        $.ajax({
            url: "/Activity/getAll.action",
            type: "get",
            dataType: "json",
            data: {
                currentPage: currentPage,
                rowsPerPage: rowsPerPage,
                searchMap: {
                    name:""
                }
            },
            beforeSend: function (XMLHttpRequest) {
                console.log("准备开始请求：");
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                console.log("请求失败：" + textStatus);
            },
            success: function (page, textStatus, jqXHR) {
                console.log("请求成功：");
                //1——清空表格数据
                $("#table tbody").empty();
                //2——循环表格加载数据
                $(page.data).each(function (i, e) {
                    var temp = '                <tr >\n' +
                        '                    <td><input name="code" value="' + e.id + '" type="checkbox"/></td>\n' +
                        '                    <td><a style="text-decoration: none; cursor: pointer;"\n' +
                        '                           onclick="window.location.href=\'detail.html?id='+e.id+'\';">' + e.name + '</a></td>\n' +
                        '                    <td>' + e.owner + '</td>\n' +
                        '                    <td>' + e.startDate + '</td>\n' +
                        '                    <td>' + e.endDate + '</td>\n' +
                        '                </tr>';
                    $("#table tbody").append(temp);
                });
                //3——初始化分页插件
                $("#page").bs_pagination({
                    currentPage: page.currentPage,          // 当前页（查询条件）
                    rowsPerPage: page.rowsPerPage,          // 每页显示的记录条数（查询条件）
                    maxRowsPerPage: page.maxRowsPerPage,    // 每页最多显示的记录条数
                    totalRows: page.totalRows,              // 总记录数
                    totalPages: page.totalPages,            // 总页数
                    visiblePageLinks: page.visiblePageLinks,// 最多显示几个卡片
                    showGoToPage: true,
                    showRowsPerPage: true,
                    showRowsInfo: true,
                    showRowsDefaultInfo: true,
                    // 点击分页卡片或者是翻页按钮执行的函数
                    onChangePage: function (event, data) {
                        // 分页查询的2个关键条件：当前页和每页条数
                        //alert("当前页是"+data.currentPage);
                        //alert("每页条数是"+data.rowsPerPage);
                        getAll(data.currentPage, data.rowsPerPage);
                    }
                });


            },
            complete: function (XMLHttpRequest, textStatus) {
                console.log("响应结果了：");
            }
        });
    }

    //组合模糊查询
    function getAllSearch(currentPage, rowsPerPage) {
        $.ajax({
            url: "/Activity/getAll.action",
            type: "get",
            dataType: "json",
            data: {
                currentPage: currentPage,
                rowsPerPage: rowsPerPage,
                searchMap: {
                    name:$("#name").val(),
                    owner:$("#owner").val(),
                    startDate:$("#startTime").val(),
                    endDate:$("#endTime").val()
                }
            },
            beforeSend: function (XMLHttpRequest) {
                console.log("准备开始请求：");
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                console.log("请求失败：" + textStatus);
            },
            success: function (page, textStatus, jqXHR) {
                console.log("请求成功：");
                //1——清空表格数据
                $("#table tbody").empty();
                //2——循环表格加载数据
                $(page.data).each(function (i, e) {
                    var temp = '                <tr >\n' +
                        '                    <td><input name="code" value="' + e.id + '" type="checkbox"/></td>\n' +
                        '                    <td><a style="text-decoration: none; cursor: pointer;"\n' +
                        '                           onclick="window.location.href=\'detail.html?id='+e.id+'\';">' + e.name + '</a></td>\n' +
                        '                    <td>' + e.owner + '</td>\n' +
                        '                    <td>' + e.startDate + '</td>\n' +
                        '                    <td>' + e.endDate + '</td>\n' +
                        '                </tr>';
                    $("#table tbody").append(temp);
                });
                //3——初始化分页插件
                $("#page").bs_pagination({
                    currentPage: page.currentPage,          // 当前页（查询条件）
                    rowsPerPage: page.rowsPerPage,          // 每页显示的记录条数（查询条件）
                    maxRowsPerPage: page.maxRowsPerPage,    // 每页最多显示的记录条数
                    totalRows: page.totalRows,              // 总记录数
                    totalPages: page.totalPages,            // 总页数
                    visiblePageLinks: page.visiblePageLinks,// 最多显示几个卡片
                    showGoToPage: true,
                    showRowsPerPage: true,
                    showRowsInfo: true,
                    showRowsDefaultInfo: true,
                    // 点击分页卡片或者是翻页按钮执行的函数
                    onChangePage: function (event, data) {
                        // 分页查询的2个关键条件：当前页和每页条数
                        //alert("当前页是"+data.currentPage);
                        //alert("每页条数是"+data.rowsPerPage);
                        getAllSearch(data.currentPage, data.rowsPerPage);
                    }
                });


            },
            complete: function (XMLHttpRequest, textStatus) {
                console.log("响应结果了：");
            }
        });
    }

    //返回当前日期
    function getDate() {
        //JavaScript获取日期对象
        var today = new Date();
        //JavaScript获取年份
        var year = today.getFullYear();
        //获取年份, 四位数
        //JavaScript获取月份
        var month = today.getMonth() + 1;
        //获取月份, 0 - 11
        //JavaScript获取天
        var day = today.getDate();
        //格式化日期
        if (month <= 9) {
            month = "0" + month;
        }
        if (day <= 9) {
            day = "0" + day;
        }
        today = year + "-" + month + "-" + day;
        //返回结果
        return today;


    }
    $(function () {

        $("#startTime").datetimepicker({
            minView: "month",
            language: 'zh-CN',
            format: 'yyyy-mm-dd',
            autoclose: true,
            todayBtn: true,
            pickerPosition: "bottom-left"
        });
        $("#startTime").val(getDate());
        $("#endTime").datetimepicker({
            minView: "month",
            language: 'zh-CN',
            format: 'yyyy-mm-dd',
            autoclose: true,
            todayBtn: true,
            pickerPosition: "bottom-left"
        });
        $("#endTime").val(getDate());



        //日期插件打开
        $("#create-startTime").datetimepicker({
            minView: "month",
            language: 'zh-CN',
            format: 'yyyy-mm-dd',
            autoclose: true,
            todayBtn: true,
            pickerPosition: "bottom-left"
        });
        //日期插件打开
        $("#create-endTime").datetimepicker({
            minView: "month",
            language: 'zh-CN',
            format: 'yyyy-mm-dd',
            autoclose: true,
            todayBtn: true,
            pickerPosition: "bottom-left"
        });


        //初始化日期
        $("#create-startTime").val(getDate());
        $("#create-endTime").val(getDate());

        //日期插件打开
        $("#edit-startTime").datetimepicker({
            minView: "month",
            language: 'zh-CN',
            format: 'yyyy-mm-dd',
            autoclose: true,
            todayBtn: true,
            pickerPosition: "bottom-left"
        });
        //日期插件打开
        $("#edit-endTime").datetimepicker({
            minView: "month",
            language: 'zh-CN',
            format: 'yyyy-mm-dd',
            autoclose: true,
            todayBtn: true,
            pickerPosition: "bottom-left"
        });
        //初始化日期
        $("#edit-startTime").val(getDate());
        $("#edit-endTime").val(getDate());


        //活动查询逻辑（带分页）
        getAll();
        //checkBox全选
        $("#selectAll").click(function () {
            $(":checkbox[name=code]").prop("checked", $("#selectAll").prop("checked"));
        });

        //活动删除***********************************************************************
        //活动删除逻辑
        $("#btnDel").click(function () {
            //jQuery数组对象
            var $delCode = $(":checkbox[name=code]:checked");

            if ($delCode.size() == 0) {
                window.alert("你没有选任何类型，无法删除");
                return;
            }

            if (!window.confirm("确定删除吗？")) {
                return;
            }
            //确定要删除了
            var codes = [];
            $delCode.each(function (i, e) {
                codes.push(e.value);
            });
            var codes = JSON.stringify(codes);


            $.ajax({
                url: "/Activity/del.action",
                type: "post",
                dataType: "json",
                contentType: "application/json",
                data: codes,
                beforeSend: function (XMLHttpRequest) {

                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {

                },
                success: function (data, textStatus, jqXHR) {
                    if (data['result'] == "success") {
                        getAll();
                    } else {
                        window.alert(data['mess']);
                    }
                },
                complete: function (XMLHttpRequest, textStatus) {

                }
            });


        });
        //活动删除End***********************************************************************

        //活动添加***********************************************************************
        //添加弹出框逻辑
        $("#btnShowAddModel").click(function () {
            //添加框显示之前加载数据(监听器一定要在显示之前编写)
            $('#createActivityModal').on("show.bs.modal", function () {
                //请求获取账户信息，填充下拉菜单
                $.ajax({
                    url: "/user/getAll.action",
                    type: "get",
                    dataType: "json",
                    beforeSend: function (XMLHttpRequest) {
                        console.log("准备开始请求：");
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        console.log("请求失败：" + textStatus);
                    },
                    success: function (data, textStatus, jqXHR) {
                        console.log("请求成功：");
                        //下来菜单清空
                        $("#create-marketActivityOwner").empty();
                        //下来菜单填充
                        $(data).each(function (i, e) {
                            var temp = '<option value="' + e.loginAct + '" >' + e.name + '</option>';
                            $("#create-marketActivityOwner").append(temp);
                        });
                    },
                    complete: function (XMLHttpRequest, textStatus) {
                        console.log("响应结果了：");
                    }
                });

            });
            //模态框关闭之后清空填写的数据(关闭事件)
            $('#createActivityModal').on('hidden.bs.modal', function (e) {
                $("#create-describe").val("");
                $("#create-cost").val("0");
                $("#create-marketActivityName").val("");
            })
            //弹出添加框（这里的弹出框使用的是bootstrap）
            $('#createActivityModal').modal({
                show: true
            });
        });
        //活动添加逻辑
        $("#btnAdd").click(function () {
            //判定名称的长度1-50
            if ($("#create-marketActivityName").val().length < 1 || $("#create-marketActivityName").val().length > 50) {
                alert("名称长度必须是1-50");
                return;
            }
            //判定描述的长度1-200
            if ($("#create-describe").val().length < 1 || $("#create-describe").val().length > 200) {
                alert("描述长度必须是1-200");
                return;
            }
            //判定成本是不是数字
            if (isNaN(parseInt($("#create-cost").val()))) {
                alert("成本必须是数字");
                return;
            }

            var st = $("#create-startTime").val();
            var et = $("#create-endTime").val();
            if (st > et) {
                alert("开始监控日期要小于结束监控日期!");
                return;
            }
            //开始请求添加
            $.ajax({
                url: "/Activity/add.action",
                type: "post",
                dataType: "json",
                data: {
                    owner: $("#create-marketActivityOwner option:selected").val(),
                    name: $("#create-marketActivityName").val(),
                    startDate: $("#create-startTime").val(),
                    endDate: $("#create-endTime").val(),
                    cost: $("#create-cost").val(),
                    description: $("#create-describe").val()
                },
                beforeSend: function (XMLHttpRequest) {
                    console.log("准备开始请求：");
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    console.log("请求失败：" + textStatus);
                },
                success: function (data, textStatus, jqXHR) {
                    console.log("请求成功：");
                    if (data['result'] == "success") {
                        //关闭模态框
                        //关闭添加框（这里的弹出框使用的是bootstrap）
                        $('#createActivityModal').modal('hide');
                        getAll();
                    } else {
                        window.alert(data['mess']);
                    }
                },
                complete: function (XMLHttpRequest, textStatus) {
                    console.log("响应结果了：");
                }
            });


        });
        //活动添加End***********************************************************************

        //活动编辑End***********************************************************************
        //修改弹出框逻辑
        $("#btnEditBefore").click(function () {

            //判断有没有选中
            //jQuery数组对象
            var $editCode = $(":checkbox[name=code]:checked");


            if ($editCode.size() == 0) {
                window.alert("你没有选任何数据，无法修改");
                return;
            }

            //添加框显示之前加载数据(监听器一定要在显示之前编写)
            $('#editActivityModal').on("show.bs.modal", function (e) {
                console.log(e);
                console.log(e.target);
                console.log($(e.target).prop("id"));
                if($(e.target).prop("id")==="editActivityModal"){
                    //请求获取账户信息，填充下拉菜单
                    $.ajax({
                        url: "/user/getAll.action",
                        type: "get",
                        dataType: "json",
                        beforeSend: function (XMLHttpRequest) {
                            console.log("准备开始请求：");
                        },
                        error: function (XMLHttpRequest, textStatus, errorThrown) {
                            console.log("请求失败：" + textStatus);
                        },
                        success: function (data, textStatus, jqXHR) {
                            console.log("请求成功：");
                            //下来菜单清空
                            $("#edit-marketActivityOwner").empty();
                            //下来菜单填充
                            $(data).each(function (i, e) {
                                var temp = '<option value="' + e.loginAct + '" >' + e.name + '</option>';
                                $("#edit-marketActivityOwner").append(temp);
                            });
                            //开始嵌套Ajax
                            //还需要选中数据
                            //还需要把所有的文本框的数据填完
                            $.ajax({
                                url: "/Activity/editBefore.action",
                                type: "get",
                                dataType: "json",
                                data: {
                                    id: $editCode.val()
                                },
                                beforeSend: function (XMLHttpRequest) {
                                    console.log("准备开始请求：");
                                },
                                error: function (XMLHttpRequest, textStatus, errorThrown) {
                                    console.log("请求失败：" + textStatus);
                                },
                                success: function (data, textStatus, jqXHR) {
                                    console.log("请求成功：");
                                    $("#edit-marketActivityName").val(data.name);
                                    $("#edit-cost").val(data.cost);
                                    $("#edit-describe").val(data.description);
                                    $("#edit-startTime").val(data.startDate);
                                    $("#edit-endTime").val(data.endDate);


                                    $("#edit-marketActivityOwner option[value='" + data.owner + "']").prop("selected", "selected");
                                },
                                complete: function (XMLHttpRequest, textStatus) {
                                    console.log("响应结果了：");
                                }
                            });
                        },
                        complete: function (XMLHttpRequest, textStatus) {
                            console.log("响应结果了：");
                        }
                    });
                }
            });

            //模态框关闭之后清空填写的数据(关闭事件)
            $('#editActivityModal').on('hidden.bs.modal', function () {
                console.log("aaaaaaaaaaaaaaaaaaaaaaaa");
            })

            //弹出修改框（这里的弹出框使用的是bootstrap）
            $('#editActivityModal').modal({
                show: true
            });

        });



        //活动修改逻辑
        $("#btnEdit").click(function () {

            //获取需要修改活动的ID
            var $editCode = $(":checkbox[name=code]:checked");
            var id=$editCode[0];

            //判定名称的长度1-50
            if ($("#edit-marketActivityName").val().length < 1 || $("#edit-marketActivityName").val().length > 50) {
                alert("名称长度必须是1-50");
                return;
            }
            //判定描述的长度1-200
            if ($("#edit-describe").val().length < 1 || $("#edit-describe").val().length > 200) {
                alert("描述长度必须是1-200");
                return;
            }
            //判定成本是不是数字
            if (isNaN(parseInt($("#edit-cost").val()))) {
                alert("成本必须是数字");
                return;
            }

            var st = $("#edit-startTime").val();
            var et = $("#edit-endTime").val();
            if (st > et) {
                alert("开始监控日期要小于结束监控日期!");
                return;
            }

            // console.log($("#edit-marketActivityName").val());
            // console.log($("#edit-startTime").val());
            // console.log($("#edit-cost").val());
            // console.log($("#edit-describe").val());

            $.ajax({
                url: "/Activity/edit.action",
                type: "post",
                dataType: "json",
                data: {
                    id:$(id).val(),
                    owner:$("#edit-marketActivityOwner option:selected").val(),
                    name:$("#edit-marketActivityName").val(),
                    startDate:$("#edit-startTime").val(),
                    endDate:$("#edit-endTime").val(),
                    cost:$("#edit-cost").val(),
                    description:$("#edit-describe").val()
                },
                beforeSend: function (XMLHttpRequest) {
                    console.log("准备开始请求：");
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    console.log("请求失败：" + textStatus);
                },
                success: function (data, textStatus, jqXHR) {
                    console.log("请求成功：");
                    if (data['result'] == "success") {
                        //关闭修改框（这里的弹出框使用的是bootstrap）
                        $('#editActivityModal').modal('hide');
                        getAll();
                    } else {
                        window.alert(data['mess']);
                    }
                },
                complete: function (XMLHttpRequest, textStatus) {
                    console.log("响应结果了：");
                }
            });


        });
        //活动修改End***********************************************************************



        //活动模糊组合查询
        $("#btnSearch").click(function () {
            getAllSearch();
        });
        //活动模糊组合查询End


        //这个是添加弹出框的关闭2按钮（目的是看看如何自己写脚本关闭弹出框）
        $("#bbb").click(function () {
            console.log("aaa");
            //关闭添加框（这里的弹出框使用的是bootstrap）
            $('#createActivityModal').modal('hide');
        });
    });
</script>